home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 / Programming Windows 95.iso / code / CHAP08 / POPPAD1.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-01  |  3.1 KB  |  90 lines

  1. /*-------------------------------------------------------
  2.    POPPAD1.C -- Popup Editor using child window edit box
  3.                 (c) Charles Petzold, 1996
  4.   -------------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
  9.  
  10. char szAppName[] = "PopPad1" ;
  11.  
  12. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  13.                     PSTR szCmdLine, int iCmdShow)
  14.      {
  15.      HWND       hwnd ;
  16.      MSG        msg ;
  17.      WNDCLASSEX wndclass ;
  18.  
  19.      wndclass.cbSize        = sizeof (wndclass) ;
  20.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  21.      wndclass.lpfnWndProc   = WndProc ;
  22.      wndclass.cbClsExtra    = 0 ;
  23.      wndclass.cbWndExtra    = 0 ;
  24.      wndclass.hInstance     = hInstance ;
  25.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  26.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  27.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  28.      wndclass.lpszMenuName  = NULL ;
  29.      wndclass.lpszClassName = szAppName ;
  30.      wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION) ;
  31.  
  32.      RegisterClassEx (&wndclass) ;
  33.  
  34.      hwnd = CreateWindow (szAppName, szAppName,
  35.                           WS_OVERLAPPEDWINDOW,
  36.                           CW_USEDEFAULT, CW_USEDEFAULT,
  37.                           CW_USEDEFAULT, CW_USEDEFAULT,
  38.                           NULL, NULL, hInstance, NULL) ;
  39.  
  40.      ShowWindow (hwnd, iCmdShow) ;
  41.      UpdateWindow (hwnd) ; 
  42.  
  43.      while (GetMessage (&msg, NULL, 0, 0))
  44.           {
  45.           TranslateMessage (&msg) ;
  46.           DispatchMessage (&msg) ;
  47.           }
  48.      return msg.wParam ;
  49.      }
  50.  
  51. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  52.      {
  53.      static HWND hwndEdit ;
  54.  
  55.      switch (iMsg)
  56.           {
  57.           case WM_CREATE :
  58.                hwndEdit = CreateWindow ("edit", NULL,
  59.                          WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
  60.                               WS_BORDER | ES_LEFT | ES_MULTILINE |
  61.                               ES_AUTOHSCROLL | ES_AUTOVSCROLL,
  62.                          0, 0, 0, 0,
  63.                          hwnd, (HMENU) 1,
  64.                          ((LPCREATESTRUCT) lParam) -> hInstance, NULL) ;
  65.                return 0 ;
  66.  
  67.           case WM_SETFOCUS :
  68.                SetFocus (hwndEdit) ;
  69.                return 0 ;
  70.  
  71.           case WM_SIZE : 
  72.                MoveWindow (hwndEdit, 0, 0, LOWORD (lParam),
  73.                                            HIWORD (lParam), TRUE) ;
  74.                return 0 ;
  75.  
  76.           case WM_COMMAND :
  77.                if (LOWORD (wParam) == 1)
  78.                     if (HIWORD (wParam) == EN_ERRSPACE ||
  79.                         HIWORD (wParam) == EN_MAXTEXT)
  80.                               MessageBox (hwnd, "Edit control out of space.",
  81.                                           szAppName, MB_OK | MB_ICONSTOP) ;
  82.                return 0 ;
  83.  
  84.           case WM_DESTROY :
  85.                PostQuitMessage (0) ;
  86.                return 0 ;
  87.           }
  88.      return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  89.      }
  90.